<template>
	<view class="botCard">
		<block class="top">
			<view class="add">
				<!-- <view class="item">
					{{merchantText}}
				</view> -->
				<view class="item">
					<image src="../../static/my/icon/shopBanner.png" mode="widthFix"></image>
				</view>
			</view>
		</block>
		<view class="intor">
			<view class="left">
				公告栏
			</view>
			<view class="right">
				欢迎加入团洗！
			</view>
		</view>
		<u-skeleton :loading="is_trila ===''" :animate="true" rows="5"></u-skeleton>
		<view class="todayInfo" v-if="is_trila == '0'||is_trila ==undefined ">
			<view class="item" v-for="(i,index) in todayList" @click="goAccess(i)">
				<view class="itemImg">
					<image :src="i.img" mode="widthFix" style="width: 70rpx;position: relative;display: inline-block;">
						<view class="tips" v-if="i.showTips" @click.stop="getTips(i.msg)"
							:style="{right: index == 1?'-4rpx;':'-20rpx'}">
							<!-- {{index}} -->
							<!-- <u-icon name="question" color="#FF954E" size="20"></u-icon> -->
							<image src="../../static/my/icon/tips.png" mode="widthFix" style="width:30rpx"></image>
						</view>
					</image>
				</view>
				<view class="topName">
					{{i.name}}
				</view>
				<view class="sum" :style="{color:i.color}">
					<text class="dolar" v-if="i.dolar">￥</text>{{i.num}}
				</view>
			</view>
		</view>
		<view class="center" v-if="is_trila == '0'||is_trila ==undefined">
			<view class="shezhi">
				<view class="">
					营业设置
				</view>
				<view class="switch">
					<u-switch v-model="status" activeColor="#2CB9A4" size="18" @change="changeStatus"></u-switch>
				</view>
			</view>
			<view class="selTime" @click="selectTime">
				<!-- <text>点击选择时间</text>
				<view class="selIcon">
					<u-icon name="arrow-right" color="#BABABA" size="20"></u-icon>
				</view> -->
				<view @click="showPop()" class="show-time">营业时间:{{defaultData.join('-')}}</view>
				<lingfeng-timepicker ref="timePop" type="time-range" @change="timeChange" :defaultData="defaultData1"></lingfeng-timepicker>
			</view>
		</view>

		<view class="commInfo">
			<view class="title" @click="goAmount">
				<text>待提现佣金</text>
				<view class="selTime">
					<text v-if="money">￥{{money}}</text>
					<view class="selIcon">
						<u-icon name="arrow-right" color="#BABABA" size="20"></u-icon>
					</view>
				</view>
			</view>
			<view class="list" v-if="is_trila == '0'||is_trila ==undefined">
				<view class="item" v-for="(i,index) in comList" :key="index" @click="goUrl(i.url)">
					<image :src="i.img" mode="" mode="widthFix"></image>
					<text>
						{{i.name}}
					</text>
				</view>
			</view>
			<view class="list" v-if="is_trila == '1'">
				<view class="item" @click="goUrl2('/pages/withdraw/WithdrawalDetails/WithdrawalDetails')">
					<image src="../../static/my/icon/6.png" mode="" mode="widthFix"></image>
					<text>
						提现记录
					</text>
				</view>
				<view class="item" @click="goUrl2('/my_pages/feigouSetting/feigouSetting')">
					<image src="../../static/my/icon/10.png" mode="" mode="widthFix"></image>
					<text>
						成为权益商户
					</text>
				</view>
			</view>
		</view>
		<!-- <u-datetime-picker :show="show" @confirm="confirm" ref="datetimePicker" @cancel='show=false'
			:minDate="minStartTime" :formatter="formatter" v-model="time" confirmColor="#00D5CE">选择有效时间
		</u-datetime-picker> -->
	</view>
</template>
<style>

</style>

<script>
	import {
		openSwitch,
		openTime,
		merchantConfig,
		census,
		getConfig,
		getMoney
	} from '@/request/api.js'
	export default {
		props: {
			botObj: {
				type: Object,
				default: () => {
					return {}
				}
			},
			isTrila:''
		},
		watch: {
			botObj: {
				handler: function(newVal) {
					// console.log(newVal, 111)
					this.defaultData[0] = newVal.merchant.start_time
					this.defaultData[1] = newVal.merchant.end_time
					this.status = newVal.merchant.openswitch == 1 ? true : false;
					this.$forceUpdate()
					// console.log(this.status,this.defaultData)
				},
				// immediate: true,
				deep: true //对象内部的属性监听，也叫深度监听
			},
			isTrila:{
				handler:function(newVal){
					this.is_trila = newVal
				}
			}
		},
		data() {

			return {
				// defaultData:['00:00:00','0:00:00'],
				money: 0,
				is_trila:'',
				defaultData: ['00:09:00','18:00:00'],
				defaultData1:{
					startTime:'09:00:00',
					endTime:'18:00:00'
				},
				merchantText: '',
				// show:false,
				// minStartTime: Number(new Date()),
				// time: Number(new Date()),
				comList: [{
						name: '扫码核销',
						url: '/my_pages/chargeOff/chargeOff',
						img: '../../static/my/icon/1.png'
					}, {
						name: '核销记录',
						url: '/my_pages/chargeList/chargeList',
						img: '../../static/icon/my/9.png'

					},{
						name: '添加商品',
						url: '/my_pages/commodityManagement/commodityManagement?type=0',
						img: '../../static/my/icon/2.png'

					}, {
						name: '订单管理',
						url: '/my_pages/orderManage/orderManage',
						img: '../../static/my/icon/3.png'
					}, {
						name: '员工管理',
						url: '/my_pages/staffManage/staffManage',
						img: '../../static/my/icon/4.png'
					}, {
						name: '意见反馈',
						img: '../../static/my/icon/5.png',
						url: '/my_pages/feedback/feedback'
					}, {
						name: '提现记录',
						img: '../../static/my/icon/6.png',
						url: '/pages/withdraw/WithdrawalDetails/WithdrawalDetails'
					}, {
						name: '数据管理',
						img: '../../static/my/icon/7.png',
						url: '/pages/my/dataManage/dataManage'
					}, {
						name: '次卡管理',
						img: '../../static/my/icon/8.png',
						url: '/my_pages/commodityManagement/commodityManagement?type=1'
					}, {
						name: '用户推广',
						img: '../../static/my/icon/12.png',
						url: '/pages/merchantPromotion/merchantPromotion'
					}, {
						name: '成为权益商户',
						url: '/my_pages/proPaySetting/proPaySetting',
						img: '../../static/my/icon/10.png',
						id:'9'
					},
					{
						name: '操作视频',
						img:'../../static/my/icon/11.png',
						url: '/my_pages/myteaching/myteaching'
					},
					{
						name: '消息管理',
						img:'../../static/my/icon/9.png',
						url: '/my_pages/information/information'
					}
				],
				status: false, //营业状态
				todayList: [{
					name: '今日订单',
					num: '0',
					img: `../../static/my/icon/top1.png?time=${new Date().getTime()}`,
					color: '#7C7EE3',
					showTips: false,
				}, {
					name: '今日营业额',
					num: '0',
					dolar: true,
					showTips: true,
					img: `../../static/my/icon/top2.png?time=${new Date().getTime()}`,
					color: '#2CB9A4',
					msg: ' 今日营业额:本店商品次卡营业收入'
				}, {
					name: '今日收益',
					num: '0',
					dolar: true,
					showTips: true,
					img: `../../static/my/icon/top3.png?time=${new Date().getTime()}`,
					color: '#FF954E',
					msg: '今日收益:每日店家核销后实际收入'
				}, {
					name: '累计用户',
					num: '0',
					showTips: false,
					img: `../../static/my/icon/top4.png?time=${new Date().getTime()}`,
					color: '#7C7EE3'
				}],
				config: {
					highest_money: 0
				}
			};
		},
		created() {
			// this.merchantConfig()
		},
		methods: {
			getTips(e) {
				this.$emit('getTips', e)
			},
			async getMoney() {
				let res = await getMoney()
				this.money = res.data
				// console.log(res,'money')
			},
			clearData() {
				this.defaultData = []
				this.todayList.forEach(item => {
					item.num = 0
				})
				this.status = false;
				this.money = 0
			},
			goAccess(i) {
				if (i.name == '今日收益') {
					uni.navigateTo({
						url: '/my_pages/orderManage/orderManage'
					})
				}
			},
			goAmount() {
				uni.switchTab({
					url: '/pages/withdraw/withdraw'
				})
			},
			async getConfig() {
				let res = await getConfig()
				this.config = res.data
				// console.log(this.config, 1111)
			},
			async census() {
				let is_trila =uni.getStorageSync('userInfo').is_trila
				this.is_trila = is_trila
				if(is_trila == 1){
					return
				}
				let res = await census()
				this.todayList[0].num = res.data.today_order
				this.todayList[1].num = res.data.today_turnover
				this.todayList[2].num = res.data.today_income
				this.todayList[3].num = res.data.member_num
				// console.log(res,1111)
			},
			async getMerchantConfig() {
				let res = await merchantConfig()
				this.merchantText = res.data.merchant_text
				
				// console.log(res)
			},
			showPop() {
				this.$refs.timePop.show();
			},
			async timeChange(val) {
				// console.log(val);
				let res = await openTime({
					start_time: val[0],
					end_time: val[1]
				});
				this.defaultData = val;
				uni.showToast({
					title: '设置成功',
					icon: 'none',
					duration: 1500
				})
				console.log(res)
			},
			changeStatus(e) {
				// console.log(e, 111)
				let code = e ? 1 : 2
				openSwitch({
					openswitch: code
				}).then(res => {
					uni.showToast({
						title: '设置成功',
						icon: 'none',
						duration: 1500
					})
				})
			},
			goUrl2(url){
				uni.navigateTo({
					url
				})
			},
			goUrl(url) {
				let token = uni.getStorageSync('shopToken')
				if (!token) {
					uni.showToast({
						icon: 'none',
						title: '请登录后操作！'
					})
					return;
				}
				if (url == '') {
					uni.showToast({
						icon: 'none',
						title: '即将上线，敬请期待！'
					})
					return;
				}
				uni.navigateTo({
					url
				})
			}
		}
	}
</script>

<style lang="scss">
	.botCard {
		padding: 20rpx;
		// padding-bottom: 70rpx;

		.intor {
			display: flex;
			justify-content: space-between;
			margin-bottom: 30rpx;

			.left {
				width: 140rpx;
				background: linear-gradient(90deg, #2775CE -55.38%, #20AFC6 123.08%);
				color: #fff;
				font-size: 32rpx;
				font-weight: 600;
				padding: 10rpx 20rpx;
				border-radius: 10rpx 0 0 10rpx;
			}

			.right {
				flex: 1;
				color: #979797;
				padding: 10rpx 20rpx;
				border-radius: 0rpx 10rpx 10rpx 0rpx;
				border: 1px solid #aecbed;
				font-size: 28rpx;
			}
		}

		.add {
			// color: #2CB9A4;
			// background: #C0EAE4;
			// box-shadow: 0px 0px 10px rgba(8, 23, 56, 0.05);
			// border-radius: 8px;
			// padding: 20rpx;

			.item {
				margin-left: -20rpx;
				margin-right: -20rpx;

				image {
					width: 100%;
				}
			}
		}

		.center {
			box-shadow: 0px 0px 10px rgba(8, 23, 56, 0.05);
			border-radius: 8px;
			padding: 20rpx;
			display: flex;
			color: #BABABA;
			justify-content: space-between;
			margin: 30rpx 0;
			font-size: 30rpx;

			.shezhi {
				display: flex;

				.switch {
					margin-left: 20rpx;
				}
			}

			.selTime {
				display: flex;
				align-items: center;

				.selIcon {
					margin-left: 20rpx;
				}
			}
		}

		.todayInfo {
			display: flex;
			justify-content: space-around;
			border-radius: 8px;
			padding: 30rpx 0;
			background: #FFFFFF;
			box-shadow: 0px 0px 5px rgba(8, 23, 56, 0.05);
			margin: 20rpx 0;

			.item {
				display: flex;
				flex-direction: column;
				align-items: center;
				position: relative;

				.itemImg {

					.tips {
						position: absolute;
						top: 0;
						right: -5px;
					}
				}

				.topName {
					color: #1D1B20;
					margin: 2rpx;
					font-size: 28rpx;
				}

				.sum {
					color: #2CB9A4;
					margin-top: 10rpx;
				}
			}
		}

		.commInfo {
			display: flex;
			box-shadow: 0px 0px 10px rgba(8, 23, 56, 0.05);
			border-radius: 8px;
			padding: 15px;
			flex-direction: column;

			.title {
				display: flex;
				justify-content: space-between;
				padding-bottom: 20rpx;
				border-bottom: 0.5rpx solid rgba(217, 217, 217, 0.6);

				.selTime {
					display: flex;
					align-items: center;
					color: #2CB9A4;

					.selIcon {
						margin-left: 20rpx;
					}
				}
			}

			.list {
				display: flex;
				// justify-content: space-between;
				flex-wrap: wrap;

				.item {
					padding: 26rpx 0;
					// box-shadow: 0px 0px 10px rgba(8, 23, 56, 0.05);
					border-radius: 8px;
					margin-top: 31rpx;
					text-align: center;
					width: 25%;
					display: flex;
					flex-direction: column;
					align-items: center;
					color: #545454;
					font-size: 26rpx;

					text {
						margin-top: 12rpx;
					}

					image {
						width: 55%;
					}
				}
			}
		}

	}
</style>